home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
- From: Dan Pop <danpop@mail.cern.ch>
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Hungarian notation
- Date: Fri, 19 Jan 1996 11:24:17 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9601191024.AA27337@dxmint.cern.ch>
- References: <4dhkae$an9@blackice.winternet.com> <821890870snz@genesis.demon.co.uk> <30fd5306.3171520@nntp.ix.netcom.com> <9601181211.AA03705@dxmint.cern.ch> <4dnf74$1sa@fountain.mindlink.net>
- X-NNTP-Posting-Host: hpl3sn03.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
-
- genew@mindlink.bc.ca (Gene Wirchenko) writes:
-
- >Dan Pop <danpop@mail.cern.ch> wrote:
- >
- >>The last statement (sort of) guarantees that any arithmetic type can be
- >>safely converted to long double, even if some information is lost in the
- >>conversion (I'm typing this text on a machine where both long and long
- >
- > I don't understand this, Dan.
- > "...safely converted..." and "...even if some information is lost
- >in the conversion..." don't go together in my understanding.
- > Do you simply mean that C won't barf or that the program won't
- >crash? Or what?
-
- By "safely converted" I meant that no overflow could possibly occur,
- even if the conversion results in a loss of precision. Here's an
- example which can be reproduced on systems using 32-bit int's and IEEE
- float's:
-
- hpl3sn02:~/tmp 73> cat test.c
- #include <stdio.h>
- #include <limits.h>
-
- main()
- {
- int i = INT_MAX - 100;
- float f = i;
-
- printf("%d %.0f\n", i, f);
- return 0;
- }
- hpl3sn02:~/tmp 74> cc test.c
- hpl3sn02:~/tmp 75> ./a.out
- 2147483547 2147483520
-
- The last bits of 'i' have been lost during the conversion, for the
- simple reason that 32 bits cannot be compressed into the 24 bits allocated
- to the mantissa of 'f'. The conversion itself is safe and no undefined
- behaviour is invoked (even if the result is implementation defined).
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-